package com.i8office.android.zhihuixinwu.module.presenter;

import com.cyan.tools.callback.SimpleCallback;
import com.i8office.android.zhihuixinwu.bean.Code;
import com.i8office.android.zhihuixinwu.module.contract.CalendarContract;
import com.i8office.android.zhihuixinwu.module.model.CalendarModel;
import com.i8office.android.zhihuixinwu.ui.schedule.EventItem;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ScheduleListPresenter extends BasePresenterImpl<CalendarContract.ScheduleListView> implements CalendarContract.ScheduleListPresenter {
    private CalendarContract.Model model;
    public ScheduleListPresenter(CalendarContract.ScheduleListView view) {
        super(view);
        model = new CalendarModel();
    }

    @Override
    public void getScheduleList(String date, int goTowards, final boolean isRefresh) {
        Map<String, String> params = new HashMap<>();
        params.put("dateFrom", date);
        params.put("goTowards",String.valueOf(goTowards));
        params.put("minTaskCount", "10");
        addDisposable(model.getScheduleList(new SimpleCallback<List<EventItem>>(mView) {
            @Override
            public void requestSuccess(List<EventItem> data) {
                mView.showEventData(isRefresh,data);
            }
            @Override
            public void requestError(String msg) {
                super.requestError(msg);
                mView.toast(msg);
            }
        }, params));
    }

    @Override
    public void removeEvent(final EventItem item) {
        Map<String, String> params = new HashMap<>();
        params.put("idList", item.getTaskID());
        addDisposable(model.removeEvent(new SimpleCallback<Code>(mView) {
            @Override
            public void requestError(String msg) {
                super.requestError(msg);
                mView.toast(msg);
            }
            @Override
            public void requestSuccess(Code data) {
                mView.deleteSuccess(item);
            }
        }, params));
    }
}
